﻿@{
    Layout = null;
    System.Collections.Concurrent.ConcurrentDictionary<string, string> errors = TempData["Error"] as System.Collections.Concurrent.ConcurrentDictionary<string, string>;
}
@model Spacebuilder.Setup.DataBaseInfoModel
<!doctype html>
<html class="no-js" lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1">
    <title>初始化数据</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="../css/bootstrap.css">
    <link rel="stylesheet" href="../css/font-awesome.css">
    <!--框架样式-->
    <link rel="stylesheet" href="../css/tnui.css">
    <link rel="stylesheet" href="../css/jh-install.css">
    <script type="text/javascript" src="../js/modernizr-2.8.3.min.js"></script>
    <script type="text/javascript" src="../js/jquery-1.12.0.min.js"></script>
    <script type="text/javascript" src="../js/main.js"></script>
    <script type="text/javascript" src="../js/lib/ajaxForm/jquery.form.js"></script>
    <script type="text/javascript" src="../js/lib/layer/layer.js"></script>
    <link rel="stylesheet" href="../js/lib/layer/skin/tnui/style.css">
    <!--[if lt IE 9]>
    <script type="text/javascript" src="../js/html5shiv.min.js"></script>
    <script type="text/javascript" src="../js/respond.js"></script>
    <![endif]-->
    <style type="text/css">
        input:-webkit-autofill, select:-webkit-autofill, textarea:-webkit-autofill {
            -webkit-box-shadow: 0 0 0px 1000px #ffffff inset !important;
        }
    </style>
</head>
<body>
    <div class="tn-doc">
        <div class="tn-content">
            <div class="container">
                <div class="jh-install-logo">
                    <img alt="..." src="../img/logo-big.png" width="124">
                    <span class="jh-install-wizard"> v5.0 安装向导</span>
                </div>
                <div class="jh-install-block">
                    <div class="jh-install-nav">
                        <ul class="list-inline">
                            <li>
                                    <span class="jh-nav-number">1</span>
                                    环境检测
                            </li>
                            <li>
                                    <span class="jh-nav-number">2</span>
                                    连接数据库
                            </li>
                            <li class="active">
                                    <span class="jh-nav-number">3</span>
                                    初始化数据
                            </li>
                            <li>
                                    <span class="jh-nav-number">4</span>
                                    安装完成
                            </li>
                        </ul>
                    </div>
                    <div class="jh-install-content">
                        @using (Html.BeginAjaxForm("_Step2_Install_InitialData", "Setup", "", FormMethod.Post, new AjaxFormOptions { OnSuccessCallBack = "CallBackSuccess" }, new { @id = "Spet3Form", @class = "form-horizontal tn-form-validation" }))
                        {
                            <fieldset>
                                <legend>初始管理员</legend>
                                <div class="form-group">
                                    <label class="col-xs-2 control-label">管理员帐号</label>
                                    <div class="col-xs-5">
                                       @Html.TextBoxFor(n => n.Administrator, new { @class = "form-control"})
                                    </div>
                                    <div class="col-xs-5">
                                        <span class="help-block">用于登录近乎</span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="" class="col-xs-2 control-label">密码</label>
                                    <div class="col-xs-5">
                                        <div class="has-feedback passwordInput">
                                            @Html.PasswordFor(n => n.UserPassword, new { @class = "form-control", @placeholder = "请输入密码" })
                                            <a href="javascript:;" class="form-control-feedback showPwd" style="color:black"><i class="fa fa-eye-slash"></i></a>
                                        </div>
                                    </div>
                                    <div class="col-xs-5">
                                        <span class="help-block">用于登录的密码</span>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <legend>站点信息</legend>
                                <div class="form-group">
                                    <label class="col-xs-2 control-label">站点名称</label>
                                    <div class="col-xs-5">
                                        @Html.TextBoxFor(n => n.SiteName, new { @class = "form-control"})
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <legend>示例数据</legend>
                                <div class="form-group">
                                    <div class="col-xs-offset-2 col-xs-10">
                                        <div class="checkbox">
                                            <label>
                                                @Html.CheckBoxFor(n => n.isInstallSampleData)
                                                安装示例数据
                                            </label>
                                        </div>
                                    </div>
                                </div> 
                            </fieldset>
                            <div class="form-group tn-mt-50">
                                <div class="col-xs-offset-2 col-xs-10">
                                    <button type="button" class="btn btn-primary btnSubmit">开始导入</button>
                                </div>
                            </div>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript">
            
        var loadindex;
        var msgindex;
        $(document).on("click", ".btnSubmit", function () {

            if ($("#Administrator").val() == "") {
                layer.msg("管理员帐号不能为空！", { icon: 2 });
                return false;
            }
            if ($("#UserPassword").val() == "") {
                layer.msg("密码不能为空！", { icon: 2 });
                return false;
            }
            if ($("#SiteName").val() == "") {
                layer.msg("站点名称不能为空！", { icon: 2 });
                return false;
            }
            msgindex = layer.msg("数据加载中...<br>大约需要3-5分钟，请耐心等待！", { icon: 8, time: 500000, shade: 0.1 });
            loadindex = layer.load();
            $('#Spet3Form').ajaxSubmit({ success: CallBackSuccess });
        });
        $(document).on("click", ".showPwd", function () {
            //密码明文切换
            var type = $("#UserPassword").attr("type");
            var value = $("#UserPassword").val();
            if (type == "password") {
                $(".passwordInput").html('@Html.TextBoxFor(n => n.UserPassword, new { @class = "form-control", @placeholder = "请输入关键字" })' +
                    '<a href="#" class="form-control-feedback showPwd" style="color:black;"><i class="fa fa-eye"></i></a>');
                $("#UserPassword").val(value);
            } else {
                $(".passwordInput").html('@Html.PasswordFor(n => n.UserPassword, new { @class = "form-control", @placeholder = "请输入关键字" })' +
                   '<a href="#" class="form-control-feedback showPwd" style="color:black;"><i class="fa fa-eye-slash"></i></a>');
                $("#UserPassword").val(value);
            }
        });
        function CallBackSuccess(data) {
            layer.close(loadindex);
            layer.close(msgindex);
            if (!$.isEmptyObject(data)) {
                var errorkey = data["errorkey"];
                var errorvalue = data["errorvalue"];
                if (!errorkey) {
                    $(".btnSubmit").hide();
                    $(".btnNext").show();
                    $(".btnSubmit").hide();
                    layer.msg("初始化数据成功！", {
                        icon: 1,
                        time: 2000//2秒关闭（如果不配置，默认是3秒）
                    }, function () {
                            layer.load();
                            window.location.href = "@CachedUrlHelper.Action("Setup_Step4", "Setup")";
                    });
                }
                else {
                    layer.alert(errorkey + "<br>" + errorvalue);
                }
            }
        }

    </script>
</body>
</html>
